package com.sfx.concurrent.demo.concurrent.pattern.Guarded;

/**
 * Description:  保护性暂停模式
 */

public class GuardedObject {
    private Object response;
    //获取结果
    public Object get(){
        synchronized (this){
            while(response==null){
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return response;
        }
    }

    //传入/产生 结果
    public void complete(Object response){
        synchronized (this) {
            this.response = response;
            this.notifyAll();
        }
    }
}